package pers.cj.pdos.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import pers.cj.pdos.controller.GoodsSnController;
import pers.cj.pdos.entity.GoodsSn;
import pers.cj.pdos.mapper.GoodsSnMapper;
import pers.cj.pdos.service.IGoodsSnService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pers.cj.pdos.utils.Utils;
import pers.cj.pdos.vo.GoodsSnVo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 商品启用sn后:入库时需要与商品1对1入库。出库时也需要一对一出库 服务实现类
 * </p>
 *
 * @author chenj
 * @since 2019-11-04
 */
@Service
public class GoodsSnServiceImpl extends ServiceImpl<GoodsSnMapper, GoodsSn> implements IGoodsSnService {
    @Autowired
    GoodsSnMapper goodsSnMapper;

    @Override
    public List<GoodsSnVo> listVoPage(String companyId, Integer page, Integer limit, String search, String storeId, String houseId, Date inDate1,Date inDate2, Date outDate1,Date outDate2,
                                      String sn,Integer status, String no, String name) {
        return goodsSnMapper.listVoPage(companyId, Utils.genPage(page,limit),limit,search, storeId,houseId, inDate1,inDate2,outDate1,outDate2,sn,status, no,name);
    }

    @Override
    public Long count(String companyId, String search, String storeId, String houseId, Date inDate1,Date inDate2, Date outDate1,Date outDate2,
                      String sn,Integer status, String no, String name) {
        return goodsSnMapper.count(companyId,search, storeId,houseId, inDate1,inDate2,outDate1,outDate2,sn,status, no,name);
    }

    @Override
    public GoodsSnVo getVoById(String id) {
        return goodsSnMapper.getVoById(id);
    }

    @Override
    public boolean checkRepeat(String goodsId, List<String> list) {
        return goodsSnMapper.countRepeat(goodsId, list) > 0;
    }

    @Override
    public List<GoodsSn> checkSnStatusOutHouseId(String goodsId, String houseId, List<String> sns) {
        return goodsSnMapper.checkSnStatusOutHouseId(goodsId, houseId, sns);
    }

    @Override
    public List<GoodsSn> listOut(Integer page, Integer limit, String goodsId, String houseId, String search) {
        return goodsSnMapper.listOut(Utils.genPage(page,limit),limit, goodsId, houseId, search);
    }

    @Override
    public Long countOut(String goodsId, String houseId, String search) {
        return goodsSnMapper.countOut(goodsId, houseId,search);
    }

    @Override
    public List<GoodsSn> listOutByGoodsTransferId(String goodsTransferId,String goodsId) {
        if (Utils.isEmpty(goodsTransferId) || Utils.isEmpty(goodsId)) {
            return new ArrayList<>();
        }
        return goodsSnMapper.listOutByGoodsTransferId(goodsTransferId,goodsId);
    }

    @Override
    public List<GoodsSn> listOutByBorrowInId(String borrowInId, String goodsId) {
        if (Utils.isEmpty(borrowInId) || Utils.isEmpty(goodsId)) {
            return new ArrayList<>();
        }
        return goodsSnMapper.listOutByBorrowInId(borrowInId,goodsId);
    }

    @Override
    public List<GoodsSn> listOutByBorrowOutId(String borrowOutId, String goodsId) {
        if (Utils.isEmpty(borrowOutId) || Utils.isEmpty(goodsId)) {
            return new ArrayList<>();
        }
        return goodsSnMapper.listOutByBorrowOutId(borrowOutId,goodsId);
    }
}
